<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item label="变量名" prop="name">
        <el-input v-model="queryParams.name" placeholder="请输入变量名" clearable @clear="getDataList"/>
      </el-form-item>
      <el-form-item label="变量标题" prop="title">
        <el-input v-model="queryParams.title" placeholder="请输入变量标题" clearable @clear="getDataList"/>
      </el-form-item>
      <el-form-item label="分组" prop="group">
        <el-input v-model="queryParams.group" placeholder="请输入分组" clearable @clear="getDataList"/>
      </el-form-item>
      <el-form-item label="变量描述" prop="tip">
        <el-input v-model="queryParams.tip" placeholder="请输入变量描述" clearable @clear="getDataList"/>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="getDataList">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button type="primary" plain icon="el-icon-plus" size="mini" @click="addOrUpdateHandle('add')">新增</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button type="success" :disabled="single" plain icon="el-icon-edit" size="mini" @click="addOrUpdateHandle()">修改</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button type="danger" :disabled="multiple" plain icon="el-icon-delete" size="mini" @click="deleteHandle">删除</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button type="primary" plain icon="el-icon-refresh" size="mini" @click="refresh">刷新缓存</el-button>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getDataList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="dataList" @selection-change="dataListSelectionChangeHandle">
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="ID" width="55" align="center" prop="id" />
      <el-table-column label="变量标题" width="200" align="center" prop="title" />
      <el-table-column label="变量名" width="300" align="center" prop="name" />
      <el-table-column label="变量值" width="400" align="center">
        <template slot-scope="scope">
          <div class="valueStyle">{{scope.row.value}}</div>
        </template>
      </el-table-column>
      <el-table-column label="分组" width="220" align="center" prop="group" />
      <el-table-column label="变量描述" width="200" align="center" prop="tip" />
      <el-table-column label="操作" fixed="right" width="200" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button size="mini" type="text" icon="el-icon-edit" @click="addOrUpdateHandle(scope.row)">修改</el-button>
          <el-button size="mini" type="text" icon="el-icon-delete" @click="deleteHandle(scope.row.id)">删除</el-button>
        </template>
      </el-table-column>
    </el-table>

    <pagination v-show="total>0" :total="total" :current-page.sync="pageNum" :page.sync="pageNum" :limit.sync="pageSize" @pagination="query" />

    <!-- 弹窗, 新增 / 修改 -->
    <add-or-update v-if="addOrUpdateVisible" ref="addOrUpdate" @refreshDataList="getDataList"></add-or-update>
  </div>
</template>

<script>

import mixinViewModule from '@/mixins/view-module'
import AddOrUpdate from './index-add-or-update'
import { refreshCache } from '@/api/basic/jkconfig'
export default {
  name: "Ntconfig",
  mixins: [mixinViewModule],
  data() {
    return {
      mixinViewModuleOptions: {
        getDataListURL: '/ntconfig/list',
        getDataListIsPage: true,
        deleteURL: '/ntconfig/remove',
        deleteIsBatch: true
      },
      queryParams: {
        name: '',
        title: '',
        group: '',
        tip: ''
      }
    };
  },
  components: {
    AddOrUpdate, //新增修改的状态弹窗
  },
  created() {

  },
  methods: {
    refresh() {
      refreshCache().then((data) => {
        if (data && data.code === 200) {
          this.$message({
            message: '刷新成功',
            type: 'success',
            duration: 1500,
            onClose: () => {
              this.getDataList()
            }
          })
        } else  {
          this.$message.error(data.msg)
        }}
      ).catch((data) =>  {})  
    }
  }
}
</script>
<style lang="scss" scoped>
.valueStyle {
  width: 400px;
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis; 
}
</style>
